package com.nuoniu.sibanyun.mapper.erp.in;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nuoniu.sibanyun.entity.erp.in.InInventoryClass;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 物料分类 Mapper 接口
 * </p>
 *
 * @author baiqiang
 * @since 2020-09-22
 */
public interface InInventoryClassMapper extends BaseMapper<InInventoryClass> {

    /**
     * 修改上级信息
     * @author 小啊刚
     * @date 2020-09-25
     */
    @Update("update scb_material_category set parent_ids=REPLACE(parent_ids, #{parentIds}, #{newParentIds}), tree_names=REPLACE(tree_names, #{treeNames}, #{newTreeNames}) " +
            "where  FIND_IN_SET(#{id}, parent_ids ) or id = #{id}")
    void updateChildrenParentIds(Long id, String parentIds, String treeNames, String newParentIds, String newTreeNames);

    /**
     * 获取物料分类
     * @author 小啊刚
     * @date 2020-09-25
     */
    @Select("select * from scb_material_category where parent_id = #{parentId}")
    List<InInventoryClass> getClassByParentId(Long parentId);

    @Select("select * from scb_material_category where class_code=#{classCode} and company_id=#{companyId}")
    InInventoryClass getByCode(InInventoryClass inInventoryClass);

    @Select("select * from scb_material_category where class_name=#{className} and company_id=#{companyId}")
    InInventoryClass getByName(InInventoryClass inInventoryClass);
}
